package com.guigu.www.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.pojo.MProceduring;
import com.guigu.www.pojo.PageVo;
import com.guigu.www.service.MProceduringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class MProceduringController {
    //生产工序过程记录
    @Autowired
    MProceduringService mProceduringService;

    @PostMapping("addmping.action")
    public Map addMDProcedure(MProceduring mProceduring) {
        Map map = new HashMap();
        boolean f = mProceduringService.save(mProceduring);
        if (f) {
            // map.put("code","0");
            map.put("msg", "添加成功");
        } else {
            // map.put("code","0");
            map.put("msg", "添加失败");
        }
        return map;
    }


    //生产工序过程记录查询
    @RequestMapping("querymProceduring.action")
    public PageVo<MProceduring> querymProceduringbypage(MProceduring mProceduring,
                                                        @RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
                                                        @RequestParam(value = "pagesize", defaultValue = "5") int pagesize) {

        //条件查询
        QueryWrapper<MProceduring> queryWrapper = new QueryWrapper<MProceduring>();

        Page<MProceduring> page = mProceduringService.page(new Page<MProceduring>(pagenum, pagesize), queryWrapper);


        PageVo<MProceduring> pageVo = new PageVo<MProceduring>();

        pageVo.setRows(page.getRecords());
        pageVo.setTotal(page.getTotal());

        return pageVo;
    }



    //登记添加数据
    @RequestMapping("/addMproceduring.action")
    public Map addMproceduring(@RequestBody MProceduring mProceduring){
        //创建map
        Map map=new HashMap();
        //调用方法
        boolean f=mProceduringService.addMproceduring(mProceduring);
        map.put("msg","登记失败");
        //判断
        if(f){
            map.put("msg","登记成功,等待审核");
        }
        return map;
    }

    //登记审核
    @RequestMapping("/updateMproceduring.action")
    public Map updateMproceduring(@RequestBody MProceduring mProceduring){
        //创建map
        Map map=new HashMap();
        //判断
        map.put("msg","登记审核失败");
        //审核
        //获取方法
        boolean f=mProceduringService.updateMproceduring(mProceduring);
        //判断
        if(f){
            map.put("msg","登记审核成功");
        }
        return  map;
    }

    //交接登记审核
    @RequestMapping("/updateMprkcedhringshow.action")
    public Map updateMprkcedhringshow(String manufactureId,int amout,int detailsNumber,int id){
        //创建map
        Map map=new HashMap();
        //判断
        map.put("msg","交接复核失败");
        //获取方法
       boolean f=mProceduringService.updateMprkcedhringshow(manufactureId,amout,detailsNumber,id);
        if(f){
            map.put("msg","交接复核成功");
        }
        return  map;
    }

}
